<template>
	<view class="content b-t">
		<!-- 空白页 -->
		<view v-if="empty===true" class="empty">
					<image src="/static/img/1/92.png" mode="aspectFit"></image>
				
					<view class="empty-tips">
						发票信息在哪里
						
					</view>
		</view>
		<image v-if="empty===false" src="/static/img/1/27.png" mode="aspectFill" class="i-header"></image>
		
		<view v-if="empty===false" class="list b-b" v-for="(item, index) in addressList" :key="index">
			
			<view class="wrapper">
				<view class="u-box">
					<text class="name">发票抬头：{{item.company_name||item.title}}</text>
					<!-- <text class="mobile clamp">纳税人识别号：{{item.itin}}</text> -->
				</view>
				<view class="u-box">
					<text class="name" v-if="item.taxpayer_code">纳税人识别号：{{item.taxpayer_code}}</text>
					<!-- <text class="mobile clamp">邮箱：{{item.email}}</text> -->
				</view>
				<view class="u-box">
					<text class="name">手机号：{{item.mobile}}</text>
				</view>
				<view class="u-box">
					<text class="name">邮箱：{{item.email}}</text>
				</view>
			
				
				
			</view>
			<text class="default" v-if="item.is_default == 1">默认</text>
			<image src="/static/img/1/93.png" mode="aspectFit" class="edit" @click="edit(item)"></image>
			
		
		</view>
		
		
		<button class="add-btn" @click="addAddress('add')">+新建</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				source: 0,
				 empty: true, //空白页现实  true|false
				addressList: []
			}
		},
		onLoad(option){
			console.log(option.source);
			this.source = option.type;
			this.refreshList()
		},
		methods: {
			//选择地址
			checkAddress(item){
				console.log(item)
				
					//this.$api.prePage()获取上一页实例，在App.vue定义
					this.$api.prePage().defaultData = item;
					uni.navigateBack()
				
			},
			addAddress(type, item){
				uni.navigateTo({
					url: `/pages/invoice/add?type=add`
				})
			},
			edit(item){
				this.$SysCache.put("invoiceData",item)
				uni.navigateTo({
					url: `/pages/invoice/add?type=edit`
				})
			},
			//添加或修改成功之后回调
			refreshList(){
				this.$Request.post4(
					this.$api.httpApi.user.getInvoiceList, {
						"uid": this.$SysCache.get('userInfo').id||this.$SysCache.get('userInfo').mid
					}
				).then(res => {
					if (res.code == 1) {
						this.addressList = res.data
						if(this.addressList.length == 0){
							this.empty = true
						}else{
							this.empty = false
						}
				
					}
				})
			}
		}
	}
</script>

<style lang='scss'>
	page{
		padding-bottom: 120upx;
		background: #f5f5f5;
	}
	.content{
		position: relative;
		.empty{
			position:fixed;
			left: 0;
			top:0;
			width: 100%;
			height: 100vh;
			padding-bottom:173upx;
			display:flex;
			justify-content: center;
			flex-direction: column;
			align-items:center;
			
			image{
				width: 249upx;
				height: 248upx;
				margin-bottom:10upx;
			}
			.empty-tips{
				display:flex;
				font-size:23upx;
				font-family:Microsoft YaHei;
				font-weight:400;
				color:rgba(102,102,102,1);
				
			}
		}
		.i-header {
			width: 100%;
			height: 10upx;
			display: block;
		}
	}
	.list{
		display: flex;
		align-items: center;
		padding: 20upx 30upx;;
		background: #fff;
		position: relative;
		
	}
	.wrapper{
		display: flex;
		flex-direction: column;
		flex: 1;
	}
	.edit{
		width:46upx;
		height:45upx;
	}
	.default{
		display: flex;
		justify-content: center;
		align-items: center;
		position: absolute;
		top:140upx;
		right: 20upx;
		width:70upx;
		height:33upx;
		background:rgba(255,255,255,1);
		border:1upx solid rgba(240, 64, 111, 1);
		border-radius:5upx;
		font-size:21upx;
		font-family:Microsoft YaHei;
		font-weight:400;
		color:rgba(240,64,111,1);
	}
	.address-box{
		display: flex;
		align-items: center;
		margin-top: 15upx;
		margin-bottom: 17upx;
		.tag{
			width:70upx;
			height:33upx;
			background:rgba(255,255,255,1);
			border:1upx solid rgba(240, 64, 111, 1);
			border-radius:5upx;
			font-size:21upx;
			font-family:Microsoft YaHei;
			font-weight:400;
			color:rgba(240,64,111,1);
			display: inline-flex;
			justify-content: center;
			align-items: center;
			margin-right: 61upx;
		}
		.tags{
			display: inline-flex;
			width:70upx;
			height:33upx;
			margin-right: 61upx;
		}
		.address{
			font-size:28upx;
			font-family:Microsoft YaHei;
			font-weight:400;
			color:rgba(102,102,102,1);
		}
	}
	.u-box{
		font-size:30upx;
		font-family:Microsoft YaHei;
		font-weight:400;
		color:rgba(102,102,102,1);
		margin-top: 10upx;
		display: flex;
		justify-content: flex-start;
		padding-left: 10upx;
		.name{
			font-size:28upx;
			font-family:Microsoft YaHei;
			font-weight:400;
			color:#444;
		}
		.mobile{
			font-size:28upx;
			font-family:Microsoft YaHei;
			font-weight:400;
			color:#666;
			max-width: 500upx;
		}
	}
	.icon-bianji{
		display: flex;
		align-items: center;
		height: 80upx;
		font-size: 40upx;
		color: $font-color-light;
		padding-left: 30upx;
	}
	
	.add-btn{
		position: fixed;
		left: 30upx;
		right: 30upx;
		bottom: 100upx;
		z-index: 95;
		display: flex;
		align-items: center;
		justify-content: center;
		width:698upx;
		height:73upx;
		background:rgba(240,64,111,1);
		border-radius:36upx;
		font-size:30upx;
		font-family:Microsoft YaHei;
		font-weight:400;
		color:rgba(255,255,255,1);
			
	}
</style>
